<template>
  <div style="margin-left: 5px;margin-right: 5px;">
    <div style="margin-top: 1%;"></div>
    <!--查询表单-->
    <el-form :inline="true" class="demo-form-inline">
      <el-form-item label="用户属性">
        <el-input v-model="cbyUserQuery.name" placeholder="用户名" />
      </el-form-item>
      <el-form-item>
        <el-input v-model="cbyUserQuery.nickName" placeholder="用户昵称" />
      </el-form-item>
      <el-form-item>
        <el-select v-model="cbyUserQuery.identityId" clearable placeholder="用户身份">
          <el-option  v-for="role in allRoles" :key="role.id" :value="role.id" :label="role.name" />
        </el-select>
      </el-form-item>
      <el-form-item label="注册时间">
        <el-date-picker v-model="cbyUserQuery.begin" type="datetime" placeholder="选择开始时间"
          value-format="yyyy-MM-dd HH:mm:ss" default-time="00:00:00" />
      </el-form-item>
      <el-form-item>
        <el-date-picker v-model="cbyUserQuery.end" type="datetime" placeholder="选择截止时间"
          value-format="yyyy-MM-dd HH:mm:ss" default-time="00:00:00" />
      </el-form-item>
      <el-button type="primary" icon="el-icon-search" @click="queryUser()">查
        询</el-button>
      <el-button type="default" @click="resetData()">清空</el-button>
    </el-form>
    <!-- 表格 -->
    <el-table :data="tableData" stripe border style="width: 100%">
      <el-table-column prop="id" label="编号" width="auto">
      </el-table-column>
      <el-table-column prop="name" label="姓名" width="auto">
      </el-table-column>
      <el-table-column prop="nickName" label="昵称">
      </el-table-column>
      <el-table-column prop="identity" label="身份">
      </el-table-column>
      <el-table-column prop="phone" label="手机号">
      </el-table-column>
      <el-table-column prop="email" label="邮箱">
      </el-table-column>
      <el-table-column prop="insertTime" label="注册时间">
      </el-table-column>
      <el-table-column label="操作" width="auto" align="center">
        <template slot-scope="scope">
          <el-button type="primary" size="mini" icon="el-icon-edit" @click="editUserById(scope.row.id)">编辑
          </el-button>
          <strong style="font-size: 24px;">|</strong>
          <el-button type="danger" size="mini" icon="el-icon-delete" @click="deleteUserById(scope.row.id)">删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-pagination background :current-page="page" :page-size="limit" :total="total"
      style="padding: 30px 0; text-align: center;" layout="total, prev, pager, next, jumper"
      @current-change="queryUser" />
  </div>
</template>

<script>
  import userApi from '../../../api/cby/user.js'
  import identityApi from '../../../api/cby/identity.js'

  export default {
    data() {
      return {
        page: 1, // 当前页
        limit: 3, // 每页数量
        total: 0, // 总记录数
        cbyUserQuery: {}, // 查询条件封装对象
        tableData: [],
        allRoles: [],
      }
    },
    created() {
      this.queryUser()
      this.getAllRoles()
    },
    methods: {
      queryUser(page = 1) {
        this.page = page
        userApi.queryUser(this.page, this.limit, this.cbyUserQuery)
          .then((response) => {
            // 请求成功
            console.log(response.data)
            this.tableData = response.data.rows;
            this.total = response.data.total;
          })
          .catch((error) => {
            console.log(error);
          });
      },
      resetData() {
        this.cbyUserQuery = {}
      },
      getAllRoles() {
        identityApi.getAllRoles()
          .then((response) => {
            // 请求成功
            console.log(response.data.allRoles)
            this.allRoles = response.data.allRoles;
          })
          .catch((error) => {
            console.log(error);
          });
      },
    }
  }
</script>

<style>
</style>
